package com.petadoption.serverclient.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.petadoption.serverclient.entity.Car;
import com.petadoption.serverclient.mapper.CarMapper;
import com.petadoption.serverclient.service.ICarService;
import com.petadoption.serverclient.vo.CarVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {
    @Resource
    private CarMapper carMapper;

    @Override
    public List<CarVO> findAll(Integer userId) {
        return carMapper.findCar(userId);
    }

    @Override
    public int updateCarCount(Car car) {
        return carMapper.update(car, new UpdateWrapper<Car>().eq("car_id", car.getCarId()));
    }

    @Override
    public int delCar(Integer carId) {
        return carMapper.delete(new QueryWrapper<Car>().eq("car_id", carId));
    }

    @Override
    public Car findCar(Integer carId) {
        return carMapper.selectById(carId);
    }

    @Override
    public int addCarProduct(Car car) {
        return carMapper.insert(car);
    }
}
